const app = getApp()

Page({
  data: {
    baseUrl: app.baseUrl,
    userHead: app.baseUrl+'img/1.jpeg',
    kvImg: app.baseUrl+'img/kv3.jpg?v=5',
    isActive:{1:'active',2:'',3:''}
  },
  onLoad: function () {
    
    this.login();
    
  },
  changtab: function (e) {
    var _isActive={1:'',2:'',3:''};
    var _id=e.currentTarget.dataset.id;
    _isActive[e.currentTarget.dataset.id]='active';
    this.setData({isActive:_isActive});
  },
  login: function(){
    var _this=this;  
    tt.login({
      force: true,
      success(res) {
        let task = tt.request({
          url: _this.data.baseUrl + "api/?c=dologin",
          data: {thecode: res.code},
          header: {"content-type": "application/x-www-form-urlencoded"},
          method: "POST",
          dataType: "json", 
          responseType: "text",
          success(res) {
            console.log(res);
            console.log(res.data);
            console.log(res.data.openid);
          },
          fail(res) {
            console.log("调用失败", res.errMsg);
          },
        });
      },
      fail(res) {
        console.log(`login 调用失败`);
      },
    });

    tt.getUserInfo({
      withCredentials: true,
      success(res) {
        console.log(res.userInfo);
        console.log(res.userInfo.nickName);
   
        _this.setData({userHead:res.userInfo.avatarUrl});
        //userHead
        console.log(`getUserInfo 调用成功 ${res.userInfo}`);
      },
      fail(res) {
        console.log(`getUserInfo 调用失败`);
      },
    });
  },
  gozbo: function(e){
      var _uname=e.detail.value['uname'];
      if('' == _uname){
        tt.showModal({
          title: "请输入主播的ID号 或者主播名"});
        return;
      }
      console.log(_uname)
  }
  
})
